home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group99a.txt
/
000218_icon-group-sender _Thu Oct 21 15:23:09 1999.msg
< prev
next >
Wrap
Internet Message Format
|
2000-09-20
|
3KB
Return-Path: <icon-group-sender>
Received: (from root@localhost)
by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) id PAA04497
for icon-group-addresses; Thu, 21 Oct 1999 15:17:38 -0700 (MST)
Message-Id: <199910212217.PAA04497@baskerville.CS.Arizona.EDU>
From: "Frank Lhota" <lhotaf@lexma.meitech.com>
To: "Blake Chapman" <blakec@pacbell.net>, <icon-group@optima.CS.Arizona.EDU>
Subject: Re: List subscription insert/removal
Date: Thu, 21 Oct 1999 11:20:28 -0000
X-Priority: 3
X-MSMail-Priority: Normal
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300
Errors-To: icon-group-errors@optima.CS.Arizona.EDU
Status: RO
I think what Gordon Peterson had in mind was using subscript ranges along
with list catenation, e.g.,
s := s[1:3] ||| [ "x" ] ||| s[3:0]
There is probably a more efficient way to do this, but this approach is
certainly straightforward.
----- Original Message -----
From: Blake Chapman <blakec@pacbell.net>
To: <icon-group@optima.CS.Arizona.EDU>
Sent: Thursday, October 21, 1999 2:21 AM
Subject: List subscription insert/removal
> Icon Project,
>
> I am trying to figure out how to insert a new element into a list,
> and remove an element from the middle of a list (not the end).
> In answer to this question previously Gordon Peterson sent
> a reply. I tried what he said and it doesn't work.
>
> My original question, that he answered, was
> "I find no routines to pluck one element out of the middle of a list, or
insert
> one in. Are there such routines?".
>
> His answer was:
> "Perhaps not, since those functions are really pretty trivial (you can use
> subscript ranges to specify sublists, making that kind of thing a simple
> expression).".
>
> I assume he meant that I can insert an element into a list the same way
> I can insert a character into a string variable. So I tried it, 4 ways;
none
> of them worked, they all produce a run-time error and abort. Here is
> the program. Though I use mere charactes or 1-char strings as list
> elements, it is just to try out list manipulation...
>
> procedure main()
> local s # it will be a list
>
> s:= ["a", "b", "c", "d"]
> WriteL(s) # this writes "abcd" as it should
> # Next, I want to insert "x" as a list element between "b" and "c" ....
> # didn't work: s[3:3]:="x"
> # didn't work: s[3:3] := ["x"]
> # didn't work: s[3+:0] := ["x"]
> s[3+:0] := "x" # didn't work; I get a run-time error and program abort
> WriteL(s)
> end
>
> procedure WriteL(L)
> local i, len
> len := *L
> i := 1
> while i <= len do { writes(L[i]) ; i +:= 1 }
> write()
> end
>
> I get the following error message when I run the above:
>
> Run-time error 111
> File E:\icon\wsource\sublist.icn; Line 28 [the line: s[3+:0] := "x" ]
> variable expected
> offending value: list_3 = []
> Traceback:
> main()
> {list_3 = [] := "x"} from line 28 in E:\icon\wsource\sublist.icn
>
> Can you tell me how to accomplish what I want?
>
> Thank You,
> Blake Chapman
>
>